import { ref, reactive, toRefs, Ref } from "vue";
import type { FormInstance, Rule } from "ant-design-vue/es/form";
import type { formInterface } from "./interface";
import { checkPassword } from "@/utils/index";
export function usePassword(formRef: any) {
  const fields = ref<formInterface>({
    password: "",
  });
  const rules: Record<string | number, Rule[]> = {
    password: [{ required: true, validator: checkPassword, trigger: "change" }],
  };

  /**
   * 点击确定按钮，校验表单
   * @returns
   */
  const useBeforeChange = () => {
    return new Promise<void>((resolve, reject) => {
      formRef.value
        .validate()
        .then((res: any) => {
          console.log(11);
        })
        .catch(() => {
          reject();
        });
    });
  };

  return {
    fields,
    rules,
    useBeforeChange,
  };
}
